//
//  ForumViewController.m
//  CarFace
//
//  Created by dlios on 15/3/23.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ForumViewController.h"
#import "DownViewController.h"

@interface ForumViewController ()<UIScrollViewDelegate>
@property(nonatomic, retain)UISegmentedControl *segmentControl;
@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)UIScrollView *smallScrollView;
@end

@implementation ForumViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;

    
//设置segmentControl控制全局
    self.segmentControl = [[UISegmentedControl alloc]initWithItems:@[@"精选日报", @"常用论坛"]];
    self.segmentControl.frame = CGRectMake(10, 20, width - 20 , 30);
    [self.segmentControl addTarget:self action:@selector(ClickSegmentcontrol:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.segmentControl];
    [_segmentControl release];
    
    
//在segmentControl下面设置一个scrollView,供segmentControl控制
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, width, height - 100)];
    self.scrollView.backgroundColor = [UIColor yellowColor];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.scrollEnabled = YES;
    self.scrollView.delegate = self;
    self.scrollView.contentSize = CGSizeMake(width * 2, 0);
//    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:self.scrollView];
    [_scrollView release];
    
//在scrollView上再建立一个小segmentControl来控制scrollView上的tableView
    self.smallScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, width - 40, 30)];
    self.smallScrollView.backgroundColor = [UIColor purpleColor];
    self.smallScrollView.scrollEnabled = YES;
    self.smallScrollView.delegate = self;
    self.smallScrollView.contentSize = CGSizeMake(1500, 30);
    self.smallScrollView.contentOffset = CGPointMake(1000, 0);
    [self.scrollView addSubview:self.smallScrollView];
    [_smallScrollView release];
    
// 设置下拉按钮
    UIButton *downButton = [UIButton buttonWithType:UIButtonTypeSystem];
    downButton.frame = CGRectMake(340, 0, 30, 30);
    downButton.backgroundColor = [UIColor cyanColor];
    [downButton setImage:[UIImage imageNamed:@"down.png"] forState:UIControlStateNormal];
    [downButton addTarget:self action:@selector(clickDownButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:downButton];
    
    
    
    
    
}

#pragma mark - segmentcontrol
- (void)ClickSegmentcontrol:(UISegmentedControl *)segmentControl
{
    [self.scrollView setContentOffset:CGPointMake(335 * self.segmentControl.selectedSegmentIndex, 0) animated:YES];
}


#pragma mark - scrollView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
 self.segmentControl.selectedSegmentIndex = scrollView.contentOffset.x / 335;
}

#pragma mark - downButton
- (void)clickDownButton:(UIButton *)button
{
    DownViewController *downVC = [[DownViewController alloc]init];
   
    [self presentViewController:downVC animated:YES completion:^{
    }];
    [downVC release];

}


















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
